package com.whxd.framework.hibernate;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class CreateTable {

	/**
	 * 根据entity自动创建数据库的java程序
	 * 
	 * @author 张世鹏
	 * @param args
	 */
	public static void main(String[] args) {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:/dbgenerator.xml");
		EntityManagerFactory entityManagerFactory = (EntityManagerFactory) ctx.getBean("entityManagerFactory");
		EntityManager em = entityManagerFactory.createEntityManager();
		
		em.getTransaction().begin();
//		em.createQuery("select u from User u").getResultList();
//		em.createQuery("select u from Role u").getResultList();
//		em.createQuery("select u from Authority u").getResultList();
//		em.createQuery("select u from Resource u").getResultList();
//		em.createQuery("select u from DhDevice u").getResultList();
//		em.createQuery("select u from DhDeviceShare u").getResultList();
		em.createQuery("select u from DhDeviceChannel u").getResultList();
		em.getTransaction().commit();
		
		em.close();
		entityManagerFactory.close();
	}

}
